package com.wn.service.db

import android.content.Context
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/**
 * @Author: wn
 * @Date: 2023/4/27 16:23
 * @Description: 提供 Room  dao 模块
 */
@Module
@InstallIn(SingletonComponent::class)
object RoomModule {
  /**
   * 提供数据库
   * @param context: Context Hilt 预置好了
   * @return DataBase
   */
  @Singleton
  @Provides
  fun provideDataBase(@ApplicationContext context: Context) =
    /*Room.databaseBuilder(application, DataBase::class.java, DB_NAME).build()*/
    DataBase.getInstance(context)

  /**
   * 提供 dao
   * @param dataBase DataBase
   * @return UserDao
   */
  @Singleton
  @Provides
  fun provideUserDao(dataBase: DataBase) = dataBase.userDao()
}